package xyz.xxin.xat.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

import xyz.xxin.xat.R;
import xyz.xxin.xat.adapter.HomeAdapter;
import xyz.xxin.xat.bean.ActivityDataBean;

public class HomeActivity extends AppCompatActivity {

    private RecyclerView menuList;
    private List<ActivityDataBean> activityDataBeans;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        findView();
        initData();
        initView();
    }

    private void initData() {
        activityDataBeans = new ArrayList<>();
        activityDataBeans.add(new ActivityDataBean(GaoDeActivity.class, "高德定位接入例子"));
        activityDataBeans.add(new ActivityDataBean(BreakPointActivity.class, "OKHTTP断点下载"));
        activityDataBeans.add(new ActivityDataBean(GLSurfaceActivity.class, "GLSurfaceView绘制"));
    }

    private void initView() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        HomeAdapter homeAdapter = new HomeAdapter(activityDataBeans, this);
        menuList.setLayoutManager(linearLayoutManager);
        menuList.setAdapter(homeAdapter);
        menuList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        homeAdapter.setItemClick(position -> {
            Intent intent = new Intent(this, activityDataBeans.get(position).getActivityClass());
            startActivity(intent);
        });
    }

    private void findView() {
        menuList = findViewById(R.id.menuList);
    }
}